﻿
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_SMS_GetNewMsg_V3]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_SMS_GetNewMsg_V3];
GO
CREATE PROCEDURE [dbo].[sproc_SMS_GetNewMsg_V3]
    @Username nvarchar(255)
AS
BEGIN
SET NOCOUNT ON

--判断是否有未读新的短消息
SELECT TOP 1 *     
    FROM 
        dbo.UDS_SMS_Msg m,
        dbo.UDS_SMS_Receiver r 
    WHERE    
        r.Receiver = @Username 
        AND m.ID = r.MsgID
        AND m.Type = 1
        AND r.IsRead = 0 
    ORDER BY
        m.sendtime asc;

END
GO